from django.shortcuts import render

# Create your views here.
from user.models import *
from user.serializers import *
from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework import status


class GetAllMenus(APIView):
    def get(self, request):
        menus = Menu.objects.filter(menus=None).all()
        menus_ser = MenuSer(menus, many=True).data
        data = []
        for i in menus_ser:
            # 获取父级下的所有子级
            menus2 = Menu.objects.filter(menus=i['id']).all()
            menus2_ser = MenuSer(menus2, many=True).data
            i['children'] = menus2_ser
            data.append(i)
        return Response({'msg': '获取成功', 'code': status.HTTP_200_OK, 'data': data})